package net.huashitong.user.web;

import com.sirdc.modules.core.web.JsonBaseController;
import com.sirdc.modules.core.web.model.JqGrid;
import com.sirdc.modules.core.web.model.Message;
import net.huashitong.user.entity.MessageReminding;
import net.huashitong.user.filter.MessageRemindingFilter;
import net.huashitong.user.service.MessageRemindingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 消息管理
 * Created by hyp1202 on 2018/7/4.
 */
@Controller
@RequestMapping("/MessageReminding")
public class MessageController extends JsonBaseController{
    @Autowired
    private MessageRemindingService messageRemindingService;
    @Override
    protected String getView(String s) {
        return null;
    }

    /**
     * 加载页面
     * @return
     */
    @RequestMapping(method = RequestMethod.GET)
    public String initPage() {
        return null;
    }

    /**
     * 查询
     * @param filter
     * @return
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST)
    public JqGrid query(@ModelAttribute MessageRemindingFilter filter) {
        //String userid = SysUserUtils.getUserId();
        List<MessageReminding> list = messageRemindingService.getMessageInfo(filter);
        return coverJqGrid(filter,list);
    }

    /**
     * 阅读消息后设置为已读
     * @param filter
     * @return
     */
    @RequestMapping(value = "/check",method = RequestMethod.POST)
    public MessageReminding check(@ModelAttribute MessageRemindingFilter filter){
        List<MessageReminding> list = messageRemindingService.getMessageInfo(filter);
        for (MessageReminding me:list) {
            me.setState("1");
        }
        return list.get(0);
    }


    /**
     * 删
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping("/delete/{id}")
    public Message deleteUser(@PathVariable List<String> id) {
        messageRemindingService.batchDelete(id);
        return coverMessage("200");
    }

    /**
     * 增
     * @param nodeNewtemplet
     * @return
     */

    @ResponseBody
    @RequestMapping(value = "/create",method=RequestMethod.POST)
    public Message addUser(@ModelAttribute MessageReminding nodeNewtemplet){
        nodeNewtemplet.setState("0");
        messageRemindingService.save(nodeNewtemplet);
        return coverMessage("200");
    }

    @RequestMapping(value = "/create")
    public String showAddUser(@ModelAttribute MessageRemindingFilter filter){
        return null;
    }

    /**
     * 改
     * @param nodeNewtemplet
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/edit",method = RequestMethod.POST)
    public Message updateUser(@ModelAttribute MessageReminding nodeNewtemplet){
        messageRemindingService.update(nodeNewtemplet);
        return coverMessage("200");
    }

    @RequestMapping(value = "/edit")
    public String showUpdateUser(@ModelAttribute MessageRemindingFilter filter){
        return null;
    }

}
